﻿/**
 *	(C) 2014 Yuanjj
 *
 *	define log class
 *
 *	histroy
 * 		2014-08-06	Yuanjj		-	create
 */

#ifndef _LOG_H_
#define _LOG_H_

#include "log.h"
#include "define.h"
#include "typedef.h"

#define		MAX_LOGS		10000

#define		L_INFO			0
#define		L_WARN			1
#define		L_ERR			2

#define		LOG_INFO		0, L_INFO				// normal log for maintainer
#define		LOG_WARN		0, L_WARN				// warn log for maintainer
#define		LOG_ERR			0, L_ERR				// error log for maintainer

#define		MAG_INFO		3, L_INFO				// normal log for manager
#define		MAG_WARN		3, L_WARN				// warn log for manager
#define		MAG_ERR			3, L_ERR				// error log for manager

#define		DBG_INFO		6, L_INFO				// normal log for developer
#define		DBG_WARN		6, L_WARN				// warn log for developer
#define		DBG_ERR			6, L_ERR				// error log for developer

class cls_log
{
public:
    cls_log();
    ~cls_log();

protected:
    QString			m_date;
    QString			m_file;
    MUTEX_LOCK		m_lock;

public:
    /**
     *	initialize log object
     */
    pem_error_t		instance();

    /**
     *	write a log into file
     */
    pem_void_t		write( pem_s32_t level, pem_s32_t type, const pem_s8_t *who, const pem_s8_t *format, ... );

protected:
    /**
     *	date need to be updated
     */
    pem_void_t		_change_date();

    /**
     *	writting log
     */
    pem_void_t 		_write( pem_s32_t type, const pem_s8_t* who, const pem_s8_t *log );
};

#endif // _LOG_H_
